import { ref } from 'vue'
import { AddNetworkTypeForm } from './types'
import { saveType } from '@/api/basic'

export default () => {
  const addNetworkTypeForm = ref<AddNetworkTypeForm>({
    id: '',
    name: '',
    parentId: '',
    status: false,
    childData: [],
  })

  const addNetworkTypeLoading = ref(false)

  const addNetworkType = async () => {
    addNetworkTypeLoading.value = true
    const res = await saveType(addNetworkTypeForm.value)
    addNetworkTypeLoading.value = false
    return res.data as { message: string; code: number; data: object; success: boolean }
  }

  const resetAddNetworkTypeForm = () => {
    addNetworkTypeForm.value = {
      id: '',
      name: '',
      parentId: '',
      status: false,
      childData: [],
    }
  }

  return {
    addNetworkTypeForm,
    addNetworkTypeLoading,
    addNetworkType,
    resetAddNetworkTypeForm,
  }
}
